#include "Common.h"
#include "MeshDrawingPolicy.h"
#include "Renderable.h"
#include "Render.h"
#include "VertexIndexData.h"

void MeshDrawingPolicy::DrawRenderable(Renderable* renderable)
{
	LPDIRECT3DDEVICE9 device = Render::Instance().getDevice();
	if (renderable->getIndexData())
	{
		const IndexData* indexData = renderable->getIndexData();
		const IndexData::PrimitiveInfo& primitiveInfo = indexData->getPrimitiveInfo();
		VERIFY_D3D(device->SetIndices(indexData->getIndexBuffer()));
		VERIFY_D3D(device->DrawIndexedPrimitive(
			(D3DPRIMITIVETYPE)primitiveInfo.PrimitiveType,
			primitiveInfo.BaseVertexIndex,
			primitiveInfo.MinVertexIndex,
			primitiveInfo.NumVertices,
			primitiveInfo.StartIndex,
			primitiveInfo.PrimCount));
	}
	else
	{
		//device->DrawPrimitive();
	}
}